package com.pan.note.im.util;

import com.pan.note.im.dto.GameDataDto;

import java.util.List;

/**
 * 多线程中获取当前线程的游戏数据工具类
 */
public class GameDataContext {

    private static final ThreadLocal<List<GameDataDto>> player = new ThreadLocal<>();
    private static final ThreadLocal<List<Integer>> food = new ThreadLocal<>();
    private static final ThreadLocal<Boolean> isStart = new ThreadLocal<>();

    /**
     * 设置游戏数据
     */
    public static void setPlayer(List<GameDataDto> dto){
        player.set(dto);
    }
    public static void setFood(List<Integer> foodSet){
        food.set(foodSet);
    }
    public static void setIsStart(Boolean flag){isStart.set(flag);}

    /**
     * 获取游戏数据
     */
    public static List<GameDataDto> getPlayer(){
        return player.get();
    }
    public static List<Integer> getFood(){
        return food.get();
    }
    public static Boolean getIsStart(){return isStart.get();}

    /**
     * 移除游戏数据
     */
    public static void removePlayer(){
        player.remove();
        food.remove();
        isStart.remove();
    }
}
